import operator
import time
from osv import osv, fields
from osv.orm import intersect
import tools.sql
from tools import config
from tools.translate import _
from mx import DateTime

class kdvn_progress(osv.osv):
    _name="kdvn.progress"
    _description="KDVN Progress"
    
    def _new_no(self, cr, uid, context={}):
        try:
            progress_line_ids=self.search(cr,uid,[('contract_id','=',context['prid'])])
            progress=self.read(cr,uid,progress_line_ids,['progress_no'],context)
            a=0
            for p in progress:
                if p['progress_no']>a:
                    a=p['progress_no']
            a=a+1            
        except:
            return 0        
        return a
    _columns={
             #'project_id':fields.many2one('account.analytic.account','Projects'),
             'contract_id':fields.many2one('kdvn.contract.client','Contract'),             
             'progress_no':fields.integer('No.'),
             'date':fields.date('Date'),
             'advanced':fields.float('Advanced'),
             'retention':fields.float('Retention'),
             'amount':fields.float('Amount'),
             'vat':fields.float('VAT'),
             }
    _defaults={
               'progress_no':_new_no,
               }
kdvn_progress()